//
//  ViewController.swift
//  daily_count
//
//  Created by 段帅 on 2018/3/28.
//  Copyright © 2018年 Sooc. All rights reserved.
//

import UIKit
import SVProgressHUD
class ViewController: UIViewController {


    @IBOutlet weak var count_text: UITextField!
    @IBOutlet weak var password_text: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

  
    @IBAction func login(_ sender: Any) {
    
        if (count_text.hasText&&password_text.hasText) {
            DSToolManager.post(URLString: severseUrl+api_login, parameters: ["count":count_text.text as AnyObject,"password":password_text.text as AnyObject]) { (data, isSucess) in
                if isSucess {
                    DSToolManager.alertSucess(message: "登录成功");
                    //把count记录本地
                    UserDefaults.standard.set(self.count_text.text, forKey: COUNT)
                    let dic =  data!["data"] as! [String:String];
                    UserDefaults.standard.set(dic["token"], forKey: TOKEN)
                    UserDefaults.standard.set(dic["token_secret"], forKey: TOKEN_SC)
                    UserDefaults.standard.set(true, forKey: IS_LOGIN)
                    DispatchQueue.main.asyncAfter(deadline: .now()+1.5, execute: { 
                        APP_DELEGATION.changeTab();
                    })
                }else{
                    DSToolManager.alertFaild(message: data!["statusCode"] as! String);
                }
            }
            

        }else{
              SVProgressHUD.showError(withStatus: "账号或者密码不能为空!");
        }
        
     
        
        
        
        
        
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.endEditing(true);
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

